<!DOCTYPE html>
<html>
<head>
    <base href="<%=basePath%>">

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>试题管理</title>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="keywords" content="">
    <link rel="shortcut icon"
          href="<%=basePath%>resources/images/favicon.ico"/>
    <link href="resources/bootstrap/css/bootstrap-huan.css" rel="stylesheet">
    <link href="resources/font-awesome/css/font-awesome.min.css"
          rel="stylesheet">
    <link href="resources/css/style.css" rel="stylesheet">

    <link href="resources/css/exam.css" rel="stylesheet">
    <link href="resources/chart/morris.css" rel="stylesheet">
    <!-- Slider Ends -->

    <!-- Javascript files -->
    <!-- jQuery -->
    <script type="text/javascript"
            src="resources/js/jquery/jquery-1.9.0.min.js"></script>
    <script type="text/javascript" src="resources/js/all.js"></script>

    <script type="text/javascript"
            src="resources/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="resources/chart/raphael-min.js"></script>
    <script type="text/javascript" src="resources/chart/morris.js"></script>
    <#--<script type="text/javascript" src="resources/js/update-user.js"></script>&ndash;&gt;-->
</head>
<body>
<header>
    <div class="container">
        <div class="row">
            <div class="col-xs-5">
                <div class="logo">
                    <h1 style="margin-top: 4px">
                        <a href="#"><img alt="" src="resources/images/logo.png"></a>
                    </h1>
                </div>
            </div>
            <div class="col-xs-7" id="login-info">
            <#--<c:choose>
                <c:when
                    test="${not empty sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.username}">-->
                <div id="login-info-user">

                <#--<a
                    href="user-detail/${sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.username}"
                    id="system-info-account" target="_blank">${sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.username}</a>-->

                </div>
            <#--	</c:when>
                <c:otherwise>
                    <a class="btn btn-primary" href="user-register">用户注册</a>
                    <a class="btn btn-success" href="user-login-page">登录</a>
                </c:otherwise>
            </c:choose>-->

            </div>
            <div class="col-xs-7" id="login-info">
                <a  href="/user/logout" style="font-size: 20px">当前登陆用户:${Curr_User.userName}</a>
            </div>
        </div>
    </div>
</header>
<!-- Navigation bar starts -->

<div class="navbar bs-docs-nav" role="banner">
    <div class="container">
        <nav class="collapse navbar-collapse bs-navbar-collapse"
             role="navigation">
            <ul class="nav navbar-nav">
                <li>
                    <a href="/user/home"><i class="fa fa-home"></i>主页</a>
                </li>
                <li>
                    <a href="/user/intopractice"><i class="fa fa-edit"></i>试题练习</a>
                </li>
                <li>
                    <a href="/user/exam"><i class="fa  fa-paper-plane-o"></i>在线考试</a>
                </li>

                <li>
                    <a href="/intousercenter"><i class="fa fa-dashboard"></i>会员中心</a>
                </li>
                <li class="active">
                    <a href="/update"><i class="fa fa-cogs"></i>个人设置</a>
                </li>
            </ul>
        </nav>
    </div>
</div>

<!-- Navigation bar ends -->

<!-- Slider starts -->

<div>
    <!-- Slider (Flex Slider) -->

    <div class="container" style="min-height: 500px;">

        <div class="row">
            <div class="col-xs-2">
                <ul class="nav default-sidenav">
                    <li class="active"><a> <i class="fa fa-cogs"></i> 基本资料
                    </a></li>
                    <li><a href="/change-password"> <i
                            class="fa fa-wrench"></i> 修改密码
                    </a></li>

                </ul>

            </div>
            <div class="col-xs-10">
                <div class="page-header">
                    <h1>
                        <i class="fa fa-cogs"></i> 基本资料
                    </h1>
                </div>
                <div class="page-content row">
                    <form class="form-horizontal" id="form-update-user"
                          style="margin-top: 40px;" method="post">

                        <div class="form-line form-username-u" style="display: block;">
                            <span class="form-label"><span class="warning-label">*</span>用户名：</span>
                            <input type="text" class="df-input-narrow" id="name-update"
                                   disabled="disabled" maxlength="20" value="${user.userName}"> <span
                                class="form-message"></span> <br>
                        </div>
                        <div class="form-line form-truename-u" style="display: block;">
                            <span class="form-label"><span class="warning-label">*</span>真实姓名：</span>
                            <input type="text" class="df-input-narrow" id="truename-update"
                                   maxlength="20" value="${user.trueName}"> <span class="form-message"></span> <br>
                        </div>
                        <div class="form-line form-national-id-u" style="display: block;">
                            <span class="form-label"><span class="warning-label">*</span>身份证号：</span>
                            <input type="text" class="df-input-narrow"
                                   id="national-id-update" maxlength="18" value="${user.nationalId}"> <span
                                class="form-message"></span> <br>
                        </div>
                        <div class="form-line form-phone-u" style="display: block;">
                            <span class="form-label"><span class="warning-label">*</span>手机：</span>
                            <input type="text" class="df-input-narrow" id="phone-update"
                                   maxlength="20" value="${user.phoneNum}"> <span class="form-message"></span> <br>
                        </div>
                        <div class="form-line form-email-u" style="display: block;">
                            <span class="form-label"><span class="warning-label">*</span>邮箱：</span>
                            <input type="text" class="df-input-narrow" id="email-update"
                                   maxlength="20" value="${user.email}"> <span class="form-message"></span> <br>
                        </div>
                        <!-- Buttons -->
                        <div class="form-group">
                            <!-- Buttons -->
                            <div class="col-md-5 col-md-offset-2">
                                <button class="btn btn-success" id="saveBtn">确认修改</button>


                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<footer>
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="copy">
                    <p>
                        ExamStack Copyright © <a href="http://www.examstack.com/"
                                                 target="_blank">ExamStack</a> - <a href="." target="_blank">主页</a>
                        | <a href="http://www.examstack.com/" target="_blank">关于我们</a> | <a
                            href="http://www.examstack.com/" target="_blank">FAQ</a> | <a
                            href="http://www.examstack.com/" target="_blank">联系我们</a>
                    </p>
                </div>
            </div>
        </div>

    </div>

</footer>


</body>

</html>
<script>

    $("#saveBtn").click(function () {
        update_account.initial();
    });
    var update_account = {

        initial : function initial() {
            this.bindSubmitForm();
        },

        bindSubmitForm : function bindSubmitForm() {
            var result = update_account.verifyInput();
            if (result){

            $.ajax({
                        type: 'POST',
                        url: 'toEdit',
                        data: {
                            userName: $("#name-update").val(),
                            trueName: $("#truename-update").val(),
                            nationalId: $("#national-id-update").val(),
                            phoneNum: $("#phone-update").val(),
                            email: $("#email-update").val(),
                        },

                        success: function (data) {
                            alert("个人信息无变动，修改失败！")
                        }, error: function (jqXHR, textStatus, errorThrown) {
                            alert("个人信息修改成功！")
                            console.log(jqXHR.responseText);
                            console.log(jqXHR.status);
                            console.log(jqXHR.readyState);
                            console.log(jqXHR.statusText);
                            /*弹出其他两个参数的信息*/
                            console.log(textStatus);
                            console.log(errorThrown);
                        }
                    })
            }
        },

        verifyInput : function verifyInput() {
            $(".form-message").empty();
            var result = true;
            //var check_u = this.checkUsername();
            var check_t = this.checkTrueName();
            var check_e = this.checkEmail();
            //var check_p = /*this.checkPassword()*/true;
            //var check_com = /*this.checkCompany();*/true;
            var check_id = this.checkNationalId();
            var check_phone = this.checkPhoneNum();
            //var check_dep = this.checkDepartment();
            result =  check_t && check_e  && check_id && check_phone;
            return result;
        },
        checkTrueName : function checkTrueName() {
            var truename = $(".form-truename-u input").val();
            if (truename == "") {
                $(".form-truename-u .form-message").text("真实姓名不能为空");
                return false;
            } else if (truename.length > 20 || truename.length < 2) {
                $(".form-truename-u .form-message").text("请保持在2-20个字符以内");
                return false;
            } else {
                var re = /[\+|\-|\\|\/||&|!|~|@|#|\$|%|\^|\*|\(|\)|=|\?|´|"|<|>|\.|,|:|;|\]|\[|\{|\}|\|]+/;
                if (re.test(truename)) {
                    $(".form-truename-u .form-message").text("只能是数字字母或者下划线的组合");
                    return false;
                } else
                    return true;

            }
            return true;
        },

        checkEmail : function checkEmail() {
            var email = $(".form-email-u input").val();
            if (email == "") {
                $(".form-email-u .form-message").text("邮箱不能为空");
                return false;
            } else if (email.length > 40 || email.length < 5) {
                $(".form-email-u .form-message").text("请保持在5-40个字符以内");
                return false;
            } else {
                var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
                if (re.test(email)) {
                    return true;
                } else {
                    $(".form-email-u .form-message").text("无效的邮箱");
                    return false;
                }

            }
            return true;
        },

        checkPhoneNum : function checkPhoneNum() {
            var phonenum = $(".form-phone-u input").val();
            if (phonenum == "") {
                $(".form-phone-u .form-message").text("号码不能为空");
                return false;
            } else {
                var re = /^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
                if (!re.test(phonenum)) {
                    $(".form-phone-u .form-message").text("手机不合法");
                    return false;
                } else
                    return true;

            }
            return true;
        },


        checkNationalId : function checkNationalId() {
            var idcard = $(".form-national-id-u input").val();
            if (idcard == "") {
                $(".form-national-id-u .form-message").text("身份证不能为空");
                return false;
            } else {
                var re = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                if (!re.test(idcard)) {
                    $(".form-national-id-u .form-message").text("身份证信息不合法");
                    return false;
                } else
                    return true;

            }
            return true;
        }
    };
</script>